/**
 * 
 */
package com.gr.staffpm.pages.notes;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.joda.time.DateTime;
import org.wicketstuff.annotation.mount.MountPath;
import org.wicketstuff.annotation.strategy.MountHybrid;

import com.gr.staffpm.StaffPMWebPage;
import com.gr.staffpm.datatypes.Activity;
import com.gr.staffpm.notes.activity.service.IActivityDaoService;
import com.gr.staffpm.security.service.UserService;


/**
 * @author Graham Rhodes 24 Feb 2011 17:25:30
 */
@MountHybrid
@MountPath(path = "secure/Notifications")
public class AllUserNotesPage extends StaffPMWebPage {

    @SpringBean(name = "activityService")
    private IActivityDaoService activityDaoService;
    @SpringBean(name = "userService")
    private UserService userService;

    public AllUserNotesPage() {
        super();
        super.onBeforeRender();

        RepeatingView groupNotes = new RepeatingView("groupNotes");

        DateTime dateOfActivity = new DateTime();
        List<Activity> activities = activityDaoService.getActivityForUserAndDate(userService.getCurrentUser(), dateOfActivity.toDate());
        for (int count = 0, i = 0; i < 31; i++) {
            if (activities != null && activities.size() > 0) {
                groupNotes.addOrReplace(new GroupNotesPanel(String.valueOf(i), dateOfActivity, new ArrayList<Activity>(activities)));
                count++;
            }
            dateOfActivity = dateOfActivity.minusDays(1);
            activities = activityDaoService.getActivityForUserAndDate(userService.getCurrentUser(), dateOfActivity.toDate());
            if (count == 6)
                break;
        }
        add(groupNotes);
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.StaffPMWebPage#getTitle()
     */
    @Override
    public String getTitle() {
        return "Your Notifications";
    }

}
